#include "../import/head.h"
#include "helper_protocol.h"
#include "../data_struct/head.h"
#include "../global/head.h"
#include "../macro/head.h"
#include "../msg/head.h"
#include "../helper_package/head.h"
#include "../helper_heart/head.h"
#include "../helper_net/head.h"
#include "../helper_tcp/head.h"
#include "../helper_udp/head.h"
#include "protocol_heart.h"
#include "protocol_ssl.h"

namespace xos_sgsj
{

    helper_protocol::helper_protocol()
    {
    }

    helper_protocol::~helper_protocol()
    {
    }

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // proc

	int helper_protocol::proc( data * pData )
	{
		int ret = 0;

		session * pSession = pData->m_pSession;
		xos::i_buf * pBuf = pData->m_pBuf;
		xos::xos_u8 uCmd = 0;

		if( 0 == ret )
		{
			ret = g_pSysData->m_os.m_pSerial->un_pack_int8( pBuf, &uCmd );
		}

		if( 0 == ret )
		{
			switch( uCmd )
			{
			case PROTOCOL_HEART:
				{
					protocol_heart obj;
					ret = obj.dis_compose( pSession, pBuf );
				}
				break;
			case PROTOCOL_SSL:
				{
					protocol_ssl obj;
					ret = obj.dis_compose( pSession, pBuf );
				}
				break;
			default:
				{
					ret = 1;
				}
				break;
			}
		}

		if( 0 != ret )
		{
			pSession->sub_ref( 1 );
		}

		pSession->sub_ref( 1 );

		if( pBuf )
		{
			pBuf->release();
			pBuf = 0;
		}

		return ret;
	}

} // xos_sgsj
